jQuery(document).ready(function($) {

   $("#resetPassForm").jobUtil("setCaptcha", {
       captchaurl: showcaptchaurl
   });

   $("#resetPassForm").validate({
      rules: {
     	 password2: {
             required: true,
             equalToInForm: "#password"
          }
       },
       messages: {
     	  password2: {
             equalToInForm: "两次填写的密码不一致"
          }
       },

       submitHandler: function(form) {
          $(form).ajaxSubmit({
            dataType: "json", 
            beforeSubmit: function(data, form, options) { 
                if(!showLoading(form))
                   return false;
                $("#regmsg", form).hide(); 
             },
             success: function(data, statusText, xhr, form) {
               try {
                  var retmsg = data; 
                  if(retmsg.error) { 
                      $("#regmsg", form).jobUtil("showError", retmsg.error); 
                      if(!/captcha_code/.test(retmsg.error))
                         $("#captcha_reload", form).trigger("click");

                  }
                  else if(retmsg.success) {

                     var html = "<div class='medium note'><span id='success_wait'>10</span>秒钟后，网页自动进入登录页面……</div>";
                     html = "<div class='successmsg lostPassMsg'>" +
                            "<div class='head'><img src='/images/3/submit_success.png'/><div class='text'>" +
                            retmsg.success + html + 
                            "</div></div>" +
                            "<div class='actions'>" + "<a href='"+loginurl+"'>返回登录页</a>" + "</div>" +
                            "</div>";

                     $("#t1", form).fadeOut(function() {
                        $(this).after(html); 
                        $("#success_wait", form).jobUtil("timerDown", function() {
                           window.location = loginurl;
                        });
                     });
                  }       
               } catch(e) {
                  return false;
               }
             }
         });
       }

   });

   $("#resetPassForm #password").blur(function() { 
      if($(this).val().length <= 0)
         return;

      if(!$(this).jobUtil("strengthCheck")) 
         $(this).nextAll(".label-warning").fadeIn();
      else
         $(this).nextAll(".label-warning").fadeOut();
   })

   $("#resetPassForm").jobUtil("showTooltip");

   // focus first text-field 
   setFocus("resetPassForm");

}); 

